﻿using System.Linq;
using Daemon.Common;
using Daemon.Common.Helpers;
using Daemon.Infrustructure.EF;
using Daemon.Repository.EF.Enums;
using Daemon.Repository.Contract;
using Daemon.Model;
using System;
using System.Linq.Expressions;
using System.Collections.Generic;

namespace Daemon.Repository.EF
{
	public class TakeAwayBoardRepository : Repository<TakeAwayBoard>, ITakeAwayBoardRepository
	{
		protected override Expression<Func<TakeAwayBoard, int>> PrimaryKeyExpression => r => r.Id;

		public TakeAwayBoardRepository(ApiDBContent context) : base(context)
		{
		}

		protected override IEnumerable<TakeAwayBoard> IncludeRelationships(IEnumerable<TakeAwayBoard> entities, ApiDBContent db)
		{
			//SetBoardArea(entities);

			//SetBoardType(entities);

			return entities;
		}

		//private void SetBoardArea(IEnumerable<TakeAwayBoard> entities)
		//{
		//	if (!RouteParameterHelper.CheckRouteParameter(RelationshipNames, TakeAwayBoardRelationShipEnum.BoardArea))
		//	{
		//		return;
		//	}

		//	var boardIds = entities.Select(r => r.AreaId).ToList();
		//	var dicBoardArea = Context.TakeAwayBoardArea.Where(r => boardIds.Contains(r.Id)).ToDictionary(r => r.Id, r => r);
		//	foreach (var entity in entities)
		//	{
		//		if (dicBoardArea.TryGetValue(entity.AreaId, out TakeAwayBoardArea area))
		//		{
		//			entity.AreaName = area.Name;
		//		}
		//	}
		//}

		//private void SetBoardType(IEnumerable<TakeAwayBoard> entities)
		//{
		//	if (!RouteParameterHelper.CheckRouteParameter(RelationshipNames, TakeAwayBoardRelationShipEnum.BoardType))
		//	{
		//		return;
		//	}

		//	var boardIds = entities.Select(r => r.TypeId).ToList();
		//	var dicBoardType = Context.TakeAwayBoardType.Where(r => boardIds.Contains(r.Id)).ToDictionary(r => r.Id, r => r);
		//	foreach (var entity in entities)
		//	{
		//		if (dicBoardType.TryGetValue(entity.AreaId, out TakeAwayBoardType boardType))
		//		{
		//			entity.TypeName = boardType.Name;
		//			entity.MaxPersonCount = boardType.MaxPersonCount;
		//			entity.MinPersonCount = boardType.MinPersonCount;
		//		}
		//	}
		//}
	}
}
